package com.acme.bankapp.service.bank;

import java.io.IOException;

import com.acme.bankapp.domain.account.CheckingAccount;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.Gender;
import com.acme.bankapp.server.BankServer;
import com.acme.exceptions.ClientDuplicateException;
import com.acme.exceptions.ClientNotExistException;
import com.acme.exceptions.InjuredFileException;
import com.acme.exceptions.NotEnoughFundsException;

public class BankApplication {
	private static Bank db = new Bank();
	static BankServer bs = new BankServer(db);
	public static void main(String[] args) {
		try {
		BankService.loadClients(BankApplication.db, "clients.txt");
		} catch (IOException | NumberFormatException | InjuredFileException | ClientDuplicateException | ClientNotExistException e) {
			e.printStackTrace();
		}
		

		try {
			BankService.addClient(db, new Client(new CheckingAccount(30,20), "Petrova", Gender.FEMALE));
		} catch (ClientDuplicateException | ClientNotExistException e1) {
			e1.printStackTrace();
		}
		
		EmailService.getEmailService().close();
		while(true) {
			try {
				bs.run();
			} catch (ClientDuplicateException | ClientNotExistException | NumberFormatException | NotEnoughFundsException e) {
				e.printStackTrace();
			}
		}
	}
}
